package com.seanLab.web;

import com.seanLab.domain.Article;
import com.seanLab.domain.Body;
import com.seanLab.dto.EditorArticleDto;
import com.seanLab.service.ArticleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.mvc.condition.MediaTypeExpression;

import java.util.Collection;

/**
 * Created by ailly on 17-8-26.
 */
@CrossOrigin(origins = "*", maxAge = 3600)
@RestController
@RequestMapping("/v1/articles")
public class ArticleController {
    @Autowired
    private ArticleService articleService;

    @RequestMapping(method = RequestMethod.GET)
    public Collection<Article> getAllArticles() {
        return this.articleService.getAllArticles();
    }

    @RequestMapping(method = RequestMethod.POST, consumes = MediaType.APPLICATION_JSON_VALUE)
    public Body insertArticle(@RequestBody EditorArticleDto editorArticleDto) {
        Body body = this.articleService.insertArticle(editorArticleDto);
        return body;
    }

}
